package com.example.receivemessage.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * ClassName:ReceiveMessage
 * Package:com.example.receivemessage.message
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/8/10-23:28
 * @Version:v1.0
 */
@Component
@Slf4j
public class ReceiveMessage {

    //接收两个队列的消息
    @RabbitListener(queues = {"queue.fanout.a", "queue.fanout.b"})
    public void receiveMsg(Message message) {

        byte[] body = message.getBody();
        String msg = new String(body);

        log.info("接收到的消息为：{}", msg);
    }

    //接收两个队列的消息--直连交换机
    @RabbitListener(queues = {"queue.direct.a", "queue.direct.b"})
    public void receiveMsgDirect(Message message) {

        byte[] body = message.getBody();
        String msg = new String(body);

        log.info("接收到的消息为：{}", msg);
    }

    //接收两个队列的消息--直连交换机
    @RabbitListener(queues = {"queue.topic.a", "queue.topic.b"})
    public void receiveMsgTopic(Message message) {

        byte[] body = message.getBody();
        String msg = new String(body);

        log.info("接收到的消息为：{}", msg);
    }

    //接收两个队列的消息--直连交换机
    @RabbitListener(queues = {"queue.headers.a", "queue.headers.b"})
    public void receiveMsgHeaders(Message message) {

        byte[] body = message.getBody();
        String msg = new String(body);

        log.info("接收到的消息为：{}", msg);
    }
}
